﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Webapiv3.Domain;
using Webapiv3.Implement;
using Webapiv3.Implement.Log;
using Webapiv3.inetrface;
using Webapiv3.Utils;
using Webapiv3.Utils.Filters;

namespace webapiv3
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<Admin3000Context>();
            services.AddScoped(typeof(ILog), typeof(Log));
            services.AddScoped(typeof(IRespository<>), typeof(Efrespository<>));
            services.AddMvc(options => options.Filters.Add<GlobalExceptionFilter>());
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
            Dbinitialize.seed(app.ApplicationServices);
        }
    }
}
